<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var check = function (nums) {
      let len = nums.length;
      let count = 0;
      for (let i = 0; i < len; i++) {
        if (nums[i] > nums[(i + 1) % len]) {
          count++;
          if (count > 1) {
            return false;
          }
        }
      }
      return true;
    };
    console.log(check([2, 1, 3, 4]));
  </script>
</body>

</html>